package com.echo.register.user.api;

import com.echo.register.common.result.Result;
import com.echo.register.common.util.AuthContextHolder;
import com.echo.register.model.user.Patient;
import com.echo.register.user.service.PatientService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.List;

/**
 * @ClassName: PatientApiController
 * @Package: com.echo.register.user.api
 * @Description: 就诊人管理接口
 * @Author 谢同学
 * @Create 2024/1/2 12:16
 * @Version 1.0
 */
@RestController
@Api(tags = "就诊人管理接口")
@RequestMapping("/api/user/patient")
public class PatientApiController {
    @Autowired
    private PatientService patientService;

    @ApiOperation("获取就诊人列表")
    @GetMapping("auth/findAll")
    public Result<List<Patient>> findAllUserId(HttpServletRequest request) {
        // 获取当前登录用户id
        Long userId = AuthContextHolder.getUserId(request);
        return Result.ok(patientService.findAllUserId(userId));
    }
    @ApiOperation("添加就诊人")
    @PostMapping("auth/save")
    public Result<?> savePatient(@RequestBody Patient patient, HttpServletRequest request) {
        // 获取当前登录用户id
        Long userId = AuthContextHolder.getUserId(request);
        patient.setUserId(userId);
        patientService.save(patient);
        return Result.ok();
    }
    @ApiOperation("根据id获取就诊人信息")
    @GetMapping("auth/get/{id}")
    public Result<Patient> getPatient(@PathVariable Long id) {
        return Result.ok(patientService.getPatientId(id));
    }
    @ApiOperation("修改就诊人信息")
    @PostMapping("auth/update")
    public Result<?> updatePatient(@RequestBody Patient patient) {
        patientService.updateById(patient);
        return Result.ok();
    }
    @ApiOperation("删除就诊人")
    @DeleteMapping("auth/remove/{id}")
    public Result<?> removePatient(@PathVariable Long id) {
        patientService.removeById(id);
        return Result.ok();
    }

    @ApiOperation(value = "获取就诊人")
    @GetMapping("inner/get/{id}")
    public Patient getPatientOrder(@PathVariable("id") Long id) {
        return patientService.getPatientId(id);
    }
}
